class RejectController < ApplicationController

  def rejectList
    
  end

  def editReject

  end

  def newReject

  end



  #管理员---驳回原因列表
  def getReject
    pageBegin =  params[:start]
    pageEnd =  params[:limit]
    count = Reject.all.count
    rejects = Reject.findAll(pageBegin,pageEnd)
    jsonstr="{totalProperty:"+count.to_s+",root:"+rejects.to_json(:only => [:id,:reson])+"}"

    render :text=>jsonstr, :layout=>false
  end

  #获取驳回原因,用于combobox
  def getRejectReason
    rejects = Reject.all
    render :text => rejects.to_json,:layout => false
  end

  def create
    begin
      reject = Reject.new
      reject.reson = params[:reson]
      reject.save!
      info = 'success'

    rescue Exception => e
      info = e.to_s
    end
    result = "{success:true,info:\"#{info}\"}"
    render :text=>result, :layout=>false
  end

  def edit
    reject = Reject.find(params[:id])
    render :text=>reject.to_json(:only => [:id,:reson]),:layout=>false
  end
  
  def update
    begin

      reject = Reject.find(params[:id])
      reject.reson = params[:reson]
      reject.save!
      info = 'success'

    rescue Exception=>e
      info = e.to_s
    end
    result = "{success:true,info:\"#{info}\"}"
    render :text=>result, :layout=>false
  end
  
  def delete  

    begin
      ids= params[:id][1..params[:id].length-2].split(',');
      for id in ids
        reject = Reject.find(id)
        reject.destroy
      end
      info = 'success'
    rescue Exception=>e
      info = e.to_s
    end
    result = "{success:true,info:\"#{info}\"}"
    render :text=>result, :layout=>false
  end

end
